<script>
	export default {
		onLaunch: function() {
			console.log('App Launch');
			// uni.clearStorageSync()
		},
		onShow: function() {
			console.log('App Show');
			if(uni.getStorageSync('member_id') ){
				this.toSign()
			}
		},
		onHide: function() {
			console.log('App Hide');
		},
		methods:{
			getQueryVariable(variable){
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1];
					}
				}
				return (false);
			},
			toSign(){
				let invite=this.getQueryVariable('invite_id')
				console.log(invite,'invite');
				let url = invite ? window.location.origin + window.location.pathname + '?invite_id=' + uni.getStorageSync('member_id') : window.location.origin + window.location.pathname
				this.$req.requestPOST(this.$api.IndexInfo.getSign, {
					url: url
				}).then(res1 => {
					console.log(res1);
					if (res1.flag == 'success') {
						let config = {
							debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
							appId: 'wxc4f5144cd4a7f83b', // 必填，公众号的唯一标识
							timestamp: res1.data.timestamp, // 必填，生成签名的时间戳
							nonceStr: res1.data.noncestr, // 必填，生成签名的随机串
							signature: res1.data.sign, // 必填，签名
							jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] // 必填，需要使用的JS接口列表
						}
						console.log(config, 'config');
						this.$wx.config(config)
						this.$wx.error(function(res) {
							// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
							// console.log();
							console.log(res,"config信息验证失败");
							uni.showToast({
								title:JSON.stringify(res.mesage),
								icon:'none'
							})
							// uni.showModal({
							// 	title: JSON.stringify(res.mesage)
							// })
						})
						this.$wx.ready(res2 => {
							console.log(res2, 'res2');
							// uni.showToast({
							// 	title:'分享成功',
							// 	icon:'none'
							// })
							this.$wx.updateAppMessageShareData({
								title: '不拘坊市', //分享的名称
								link: window.location.origin + window.location.pathname+'?invite_id=' + uni.getStorageSync('member_id'),
								desc: '不拘坊市', // 分享描述
								imageUrl: 'https://libc-ddanm.bujufangshi.com/logo.jpg',
								success: function(res) {
									console.log(res, '成功updateAppMessageShareData');
								},
								fail(res) {
									console.log(res, '失败updateAppMessageShareData');
								}
							})
							this.$wx.updateTimelineShareData({
								title: '不拘坊市', //分享的名称
								link:  window.location.origin + window.location.pathname+'?invite_id=' + uni.getStorageSync('member_id'),
								desc: '不拘坊市', // 分享描述
								imageUrl: 'https://libc-ddanm.bujufangshi.com/logo.jpg',
								success: function(res) {
									console.log(res,
										'成功updateAppMessageShareData');
								},
								fail(res) {
									console.log(res, '失败updateAppMessageShareData');
								}
							})
						})
					}
				})
			}
		}
	};
</script>

<style lang="scss">
	@import '@/uni_modules/uview-plus/theme.scss';
	/************************************************************
  ** 请将全局样式拷贝到项目的全局 CSS 文件或者当前页面的顶部 **
  ** 否则页面将无法正常显示                                  **
  ************************************************************/

	html {
		font-size: 16px;
	}

	body {
		margin: 0;
		font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
			'Droid Sans', 'Helvetica Neue', 'Microsoft Yahei', sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	view,
	image,
	text {
		box-sizing: border-box;
		flex-shrink: 0;
	}

	#app {
		width: 100vw;
		height: 100vh;
	}

	.flex-row {
		display: flex;
		flex-direction: row;
	}

	.flex-col {
		display: flex;
		flex-direction: column;
	}

	.justify-start {
		justify-content: flex-start;
	}

	.justify-end {
		justify-content: flex-end;
	}

	.justify-center {
		justify-content: center;
	}

	.justify-between {
		justify-content: space-between;
	}

	.justify-around {
		justify-content: space-around;
	}

	.justify-evenly {
		justify-content: space-evenly;
	}

	.items-start {
		align-items: flex-start;
	}

	.items-end {
		align-items: flex-end;
	}

	.items-center {
		align-items: center;
	}

	.items-baseline {
		align-items: baseline;
	}

	.items-stretch {
		align-items: stretch;
	}

	.self-start {
		align-self: flex-start;
	}

	.self-end {
		align-self: flex-end;
	}

	.self-center {
		align-self: center;
	}

	.self-baseline {
		align-self: baseline;
	}

	.self-stretch {
		align-self: stretch;
	}

	.flex-1 {
		flex: 1 1 0%;
	}

	.flex-auto {
		flex: 1 1 auto;
	}

	.grow {
		flex-grow: 1;
	}

	.grow-0 {
		flex-grow: 0;
	}

	.shrink {
		flex-shrink: 1;
	}

	.shrink-0 {
		flex-shrink: 0;
	}

	.relative {
		position: relative;
	}
</style>